home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Shared Library Manager / ASLM Developer Tools / Tools / LinkSharedLibrary < prev    next >
Encoding:
Text File  |  1996-11-19  |  6.3 KB  |  221 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        LinkSharedLibrary
  3. #
  4. #    Contains:    Script to link a shared library
  5. #
  6. #    Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  7. #
  8. #
  9.  
  10. Set OutFile        ""
  11. Set InObj        ""
  12. Set SymFile        ""
  13. Set XCoffSymFile 0
  14. Set PPCLinkOpts    "-outputformat xcoff"
  15. Set MakeSymOptions    "-w -r"
  16. Set MakePefOptions    ""
  17. Set Error        0
  18. Set NoMerge        0
  19. Set Symbols        0
  20. Set model        "-model far"
  21. Set PPC            0
  22. if "{TempFolder}" !~ //
  23.     Set Scratch "{TempFolder}"
  24. else if "{CPlusScratch}" !~ //
  25.     Set Scratch "{CPlusScratch}"
  26. else
  27.     Set Scratch "`directory`"
  28. end
  29.  
  30. LOOP
  31.     If "{1}" == "" || "{1}" !~ /-≈/
  32.         Break;
  33.     Else If "{1}" =~ /-obj/
  34.         Set InObj "{2}"; Shift 2; Continue
  35.     Else If "{1}" =~ /-lib/
  36.         Set OutFile "{2}";    Shift 2; Continue
  37.     Else If "{1}" =~ /-link/
  38.         Shift; Break;
  39.     Else If "{1}" =~ /-near/
  40.         Set model "-model near"
  41.     Else If "{1}" =~ /-far/
  42.         Set model "-model far"
  43.     Else If "{1}" =~ /-noMerge/
  44.         Set NoMerge 1
  45.     Else If "{1}" =~ /-powerpc/
  46.         Set PPC 1
  47.     Else If "{1}" =~ /-68K/
  48.         Set PPC 0
  49.     Else If "{1}" =~ /-makesym/
  50.         Set MakeSymOptions "{2}"; Shift 2; Continue
  51.     Else If "{1}" =~ /-makepef/
  52.         Set MakePefOptions "{2}"; Shift 2; Continue
  53.     Else If "{1}" =~ /-map/
  54.         Set MapFile "{2}"; Shift 2; Set UsrMap 1; Continue
  55.     Else If "{1}" =~ /-sym/
  56.         If "{2}" =~ /on/
  57.             Set Symbols 1
  58.             Set SymOption "-sym on"
  59.         Else If "{2}" =~ /off/
  60.             Set Symbols 0
  61.         Else
  62.             Set Error 1
  63.             Break;
  64.         End
  65.         Shift
  66.     Else If "{1}" =~ /-symfile/
  67.         Set SymFile "{2}"; Shift 2; Continue
  68.     Else If "{1}" =~ /-xcoffsymfile/
  69.         Set XCoffSymFile 1
  70.     Else If "{1}" =~ /-oldPPCLink/
  71.         Set PPCLinkOpts ""
  72.     Else
  73.         Set Error 1
  74.         Break;
  75.     End
  76.     Shift
  77. End
  78.  
  79. If "{MapFile}" == ""
  80.     Set MapFile        "{Scratch}SharedLibTemp.Map" 
  81.     Set UsrMap        0
  82. End
  83.  
  84. If "{InObj}" == "" || "{OutFile}" == ""
  85.     Set Error 1
  86. End
  87. If {Error}
  88.         Echo "Usage: LinkSharedLibrary -lib <OutputLibrary>"
  89.         Echo "       -obj <ObjectRootName>"
  90.         Echo "       -sym on|off -symfile <ObjectRootName> -xcoffsymfile"
  91.         Echo "       -map <MapFileName> -oldPPCLink"
  92.         Echo "       -noMerge -powerpc -68k"
  93.         Echo "         -link <Parameters for the link>"
  94.         Echo ""
  95.         Echo "Must be used after using BuildSharedLibrary"
  96.         Echo ""
  97.         Echo "    The name after the -obj flag describes the base name for all of"
  98.         Echo "    the files resulting from invoking this tool.  The following"
  99.         Echo "    are added to the base name you supply:"
  100.         Echo "       .lib.o - The actual shared library object file"
  101.         Echo "       .libr.r - Resource to rez with the shared library resource"
  102.         Echo "       .deps - File used to create the dependency ('libi') resource"
  103.         Echo "       .init.o - Initialization code for the library\n"
  104.         Echo "       .ia.o - Initialization code for the library\n"
  105.         Echo "    This should be the same name you passed to the BuildSharedLibrary"
  106.         Echo "    Script"
  107.         Echo ""
  108.         Echo "    Everything after -link will be passed to the linker directly."
  109.         Echo "    The list of libraries to link with must be last"
  110.         Echo "    or after the -link switch."
  111.         Echo "    The link automatically merges segments Main, STDCLIB, STDIO,"
  112.         Echo "    CSANELib, SANELIB, %Complex, SADEV, and INTENV unless you"
  113.         Echo "    specify the NoMerge flag"
  114.         Exit 10
  115. End
  116. If {Progress}
  117.     Echo "∂t∂tCreating shared library ∂"{OutFile}∂""
  118. End
  119.  
  120. If NOT {NoMerge} && NOT {PPC}
  121.     Set SegMerge "-sg Main=%Complex,CSANELib,CTYPE,INTENV,SADEV,SANELIB,SCCOMPLEX,SCMATH,SCMEM,SCPP,SCSTDIO,SCSTREAM,SCSTRING,SCTIME,STDCLIB,STDIO,ZMEM,ZPAGE,ZSTRING,ZTIME,ZZTC"
  122. Else
  123.     Set SegMerge ""
  124. End
  125.  
  126. delete -i "{Scratch}SharedLibTemp.libr.r" "{Scratch}SharedLibTemp.RSRC" "{Scratch}SharedLibTemp.pef"
  127.  
  128. SetFile -c 'MPS ' -t TEXT "{InObj}.libr.r"
  129.  
  130. duplicate -y "{InObj}.libr.r" "{Scratch}SharedLibTemp.libr.r"
  131. Delete -i "{Scratch}SharedLibTemp.RSRC.SYM"
  132.  
  133. If "`Exists -f "{InObj}.deps"`"
  134.     Set HaveDeps 1
  135. Else
  136.     Set HaveDeps 0
  137. End
  138.  
  139. If {WantProg}
  140.     Echo "∂t∂t# Linking Library resource"
  141. End
  142.  
  143. Set AsmInitFile ""
  144. If "`Exists "{InObj}.ia.o"`"
  145.     Set AsmInitFile "{InObj}.ia.o"
  146. End
  147.  
  148. Set Result 0
  149.  
  150. If {PPC}
  151.     If {UsrMap} || {HaveDeps}
  152.         Set MapOption "-map ∂"{MapFile}∂""
  153.     End
  154.     
  155.     PPCLink {PPCLinkOpts} {SymOption} -w -main DynamicCodeEntry -o "{Scratch}SharedLibTemp.xcoff" ∂
  156.         "{InObj}.init.o" "{AsmInitFile}" "{InObj}.lib.o" ∂
  157.         {MapOption} {"Parameters"} || Set Result {Status}
  158.     If {Result} == 0
  159.         makepef "{Scratch}SharedLibTemp.xcoff" -o "{Scratch}SharedLibTemp.pef" ∂
  160.             -l StdCLib.xcoff=StdCLib -l InterfaceLib.xcoff=InterfaceLib -l MathLib.xcoff=MathLib ∂
  161.             {MakePefOptions} || Set Result {Status}
  162.         If {Result} == 0 && {Symbols} && !{XCoffSymFile}
  163.             MakeSym {MakeSymOptions} -o "{Scratch}SharedLibTemp.RSRC.SYM" "{Scratch}SharedLibTemp.xcoff" 
  164.             SetFile -c 'R2Db' -t 'MPSY' "{Scratch}SharedLibTemp.RSRC.SYM"
  165.         End
  166.     End
  167. Else
  168.     If {UsrMap} || {HaveDeps}
  169.         Set MapOption "-map >∂"{MapFile}∂""
  170.     End
  171.     
  172.     Link {model} {SymOption} -mf -d -t rsrc -c RSED ∂
  173.         -sg %A5Init=A5Init -ra %A5Init=resLocked -m DynamicCodeEntry ∂
  174.         -o "{Scratch}SharedLibTemp.RSRC" ∂
  175.         "{InObj}.init.o" "{AsmInitFile}" "{InObj}.lib.o" ∂
  176.         {SegMerge} {"Parameters"} {MapOption} || Set Result {Status}
  177. End
  178.  
  179. If {Result} == 0
  180.     If {HaveDeps}
  181.         If {PPC}
  182.             "{SLMTools}CreateLibraryLoadRsrcPPC" -map "{Scratch}SharedLibTemp.xcoff"  -out "{Scratch}SharedLibTemp.libr.r" ∂
  183.                 -resid SLMID -a -readx "{InObj}.deps"
  184.         Else
  185.             "{SLMTools}CreateLibraryLoadRsrc" -map "{MapFile}" -out "{Scratch}SharedLibTemp.libr.r" ∂
  186.                 -resid SLMID -a -readx "{InObj}.deps"
  187.         End
  188.     End
  189.     duplicate -y "{Scratch}SharedLibTemp.libr.r" "{InObj}.libr.r"
  190.     
  191.     If {Symbols} && {XCoffSymFile}
  192.         duplicate -y "{Scratch}SharedLibTemp.xcoff" "{SymFile}"
  193.         delete -i -y "{Scratch}SharedLibTemp.xcoff"
  194.     End
  195.  
  196.     If ("`Exists -f "{Scratch}SharedLibTemp.RSRC.SYM"`") && ("{SymFile}" !~ //)
  197.         duplicate -y "{Scratch}SharedLibTemp.RSRC.SYM" "{SymFile}"
  198.         Delete -i "{Scratch}SharedLibTemp.RSRC.SYM"
  199.     End
  200.     
  201.     Delete -i "{OutFile}" ∑∑ Dev:Null
  202.     
  203.     If {PPC}
  204.         Echo "read SLMType (SLMID, SLMName, purgeable) ∂"{Scratch}SharedLibTemp.pef∂";" >> "{Scratch}SharedLibTemp.libr.r"
  205.     Else
  206.         Echo "Include ∂"{Scratch}SharedLibTemp.RSRC∂" 'CODE' as SLMType;" >> "{Scratch}SharedLibTemp.libr.r"
  207.         Echo "Delete SLMType (∂"32-bit bootstrap∂");" >> "{Scratch}SharedLibTemp.libr.r"
  208.     End
  209.     
  210.     Rez -a -t libr -c OMGR -rd ∂
  211.         -o "{OutFile}" "{Scratch}SharedLibTemp.libr.r"
  212.     SetFile -a ib "{OutFile}"
  213. End
  214.  
  215. delete -i "{Scratch}SharedLibTemp.libr.r" "{Scratch}SharedLibTemp.RSRC" "{Scratch}SharedLibTemp.pef"
  216. If {HaveDeps} != 0 AND {UsrMap} == 0
  217.     Delete -i "{MapFile}"
  218. End
  219.  
  220. exit {Result}
  221.